<template>
  <s-layout
    @loginEnd="loginEnd"
    navbar="custom1"
    :bgStyle="{
	 color: '#F8F8F8'
	}"
    onShareAppMessage
  >
    <!-- <assNavbar
      :title="state.type==0?'商户入驻':'代理商户入驻'"
      :background="{img: 'none',BGcolor: '#fff'}"
    ></assNavbar> -->
    <view
      class="status"
      v-if="state.status !== null"
    >
      <view class="status-top ss-p-l-50">
        <!-- 等待审核 -->
        <view
          class="status-wait ss-flex align-center"
          v-if="state.status === 0"
        >
          <image
            class="status-wait-image ss-m-r-30"
            src="https://liuliangbenben.oss-cn-hangzhou.aliyuncs.com/storage/ugc/20250326/135823c277d6aa8f2260e3451a462e9e.png"
          >
          </image>

          <view
            class="flex"
            style="display: flex; justify-content: start; align-items: center"
          >
            <view
              v-if="state.form.sigin_link == null"
              class="status-wait-title"
            >提交成功,请等待审核</view>
            <view
              v-if="state.form.sigin_link != null"
              class="status-wait-title"
            >初审成功，等待签约</view>
          </view>
        </view>
        <!-- 审核成功 -->
        <view
          class="status-wait ss-flex align-center"
          v-if="state.status === 1"
        >
          <image
            class="status-wait-image ss-m-r-30"
            src="https://liuliangbenben.oss-cn-hangzhou.aliyuncs.com/storage/ugc/20250326/135823c277d6aa8f2260e3451a462e9e.png"
          >
          </image>
          <view>
            <view class="status-wait-title">审核通过</view>
            <view
              v-if="headerObj.agreement==0||headerObj.real_name==0||headerObj.elec==0"
              class="status-wait-tips ss-m-t-10"
              style="color:#3D3D3D"
            >
              审核已通过，请进行
              <span
                @tap="signCode"
                style="color:#003AD9;text-decoration:underline;"
              >商户签约></span>
            </view>

            <view
              v-if="headerObj.agreement==1&&headerObj.real_name==1&&headerObj.elec==1"
              class="status-wait-tips ss-m-t-10"
              style="color:#3D3D3D"
            >
              恭喜您进件成功！
            </view>
          </view>
        </view>

        <!-- 审核失败 -->
        <view
          class="status-wait ss-flex align-center"
          v-if="state.status === 2"
        >
          <image
            class="status-wait-image ss-m-r-30"
            src="https://liuliangbenben.oss-cn-hangzhou.aliyuncs.com/storage/ugc/20250326/926e5911ce12a3389b0296efd3929b3f.png"
          >
          </image>
          <view>
            <view class="status-wait-title">审核失败</view>
            <view class="status-wait-tips ss-m-t-10">失败原因：{{ state.form.remark }}</view>
          </view>
        </view>
        <!-- 已解除合作 -->
        <!-- <view class="status-wait ss-flex align-center" v-if="state.status < 0">
            <image
              class="status-wait-image ss-m-r-30"
              src="https://liuliangbenben.oss-cn-hangzhou.aliyuncs.com/storage/ugc/20250326/926e5911ce12a3389b0296efd3929b3f.png"
            >
            </image>
            <view>
              <view class="status-wait-title">已解除合作</view>
            </view>
          </view> -->
      </view>
      <view class="status-bottom"></view>
    </view>
    <view class="form-box">
      <uni-forms
        ref="form"
        :modelValue="state.form"
        :rules="rules"
        label-width="90"
      >
        <view class="content-box">
          <view
            class="header-title"
            v-if="state.type!=0||state.bd_no"
          >BD信息</view>
          <view
            v-if="!state.seeAccount&&(state.type!=0||state.bd_no)"
            class="formItem-box"
          >
            <uni-forms-item
              label="BD姓名"
              name="agency_name"
            >
              <view class="form-box-input-item">
                <input
                  :disabled="true"
                  type="text"
                  v-model="state.form.agency_name"
                  placeholder=""
                />
              </view>
            </uni-forms-item>
            <uni-forms-item
              label="BD手机号"
              name="agency_mobile"
            >
              <view class="form-box-input-item">
                <input
                  :disabled="true"
                  type="number"
                  :maxlength="11"
                  v-model="state.form.agency_mobile"
                  placeholder=""
                />
              </view>
            </uni-forms-item>
            <uni-forms-item
              label="商户类型"
              name="serve"
              required
            >
              <view class="form-box-input-item">
                <radio-group
                  @change="radioChange"
                  class="ss-flex flex-wrap font-1 ss-p-t-14 radio-box"
                  style="width:370rpx;color:#424242"
                >
                  <label
                    class="uni-list-cell uni-list-cell-pd ss-flex ss-m-l-10"
                    v-for="(item) in radioFormList"
                    :key="item.value"
                  >
                    <radio
                      color="#003288"
                      :disabled="state.disabled"
                      style="transform: scale(0.5)"
                      :value="String(item.value)"
                      :checked="state.form.serve == item.value"
                    />
                    <view
                      class="font-1"
                      style="color:gray"
                    >{{item.label}}</view>
                  </label>
                </radio-group>
              </view>
            </uni-forms-item>
          </view>
        </view>
        <view class="content-box">
          <view class="header-title">{{state.type!=0||state.bd_no?'BD代入驻':'商户信息'}}</view>
          <view
            v-if="!state.seeAccount"
            class="bg-white"
          >
            <view class="formItem-box">
              <!-- <uni-forms-item
                label="商户类型"
                name="identity"
                required
              >
                <picker
                  @change="bindPickerChange($event,'identity')"
                  :value="state.form.identity"
                  :range="radioList1"
                  range-key="name"
                >
                  <view class="form-box-input-item form-top-style">
                    <view
                      style="font-size:30rpx;"
                      class="text-color"
                    >{{ filterText(radioList1,state.form.identity) }}</view>
                    <uni-icons
                      type="forward"
                      size="22"
                      color="#999999"
                    ></uni-icons>
                  </view>
                </picker>
              </uni-forms-item> -->
              <uni-forms-item
                label="商户简称"
                name="merchant_name"
                required
                class="none-border"
              >
                <view class="form-box-input-item">
                  <input
                    :disabled="state.disabled"
                    type="text"
                    v-model="state.form.merchant_name"
                    placeholder="请输入商户简称"
                    @input="setValue($event,'merchant_name')"
                  />
                </view>
              </uni-forms-item>
              <view class="footer-message">
                商户简称申请后30天内只能修改一次，提交时请仔细确认
              </view>
              <uni-forms-item
                label="行业类型"
                name="mcc_code"
                required
              >
                <view class="form-box-input-item ">
                  <view
                    class="form-item ss-flex justify-between align-center b-b-c"
                    @tap="state.disabled?null:state.showMcc = true"
                  >
                    <view class="uni-input text-color">{{ state.mcc_name || '请选择行业类型' }}</view>
                  </view>
                </view>
              </uni-forms-item>
              <uni-forms-item
                label="平台类目"
                name="store_category_id"
                required
              >
                <view
                  class="form-box-input-item "
                  @click="state.disabled?null:state.showType=true"
                >
                  <view
                    style="font-size:30rpx;"
                    class="text-color"
                  >{{ state.shop_type_txt || '请选择平台类目' }}</view>
                  <uni-icons
                    type="forward"
                    size="22"
                    color="#999999"
                  ></uni-icons>
                </view>
              </uni-forms-item>

              <uni-forms-item
                label="商家电话"
                name="mobile"
                required
              >
                <view class="form-box-input-item">
                  <!-- :disabled="state.disabled"  -->
                  <input
                    type="number"
                    :disabled="state.type==0||state.form.id||state.disabled"
                    :maxlength="11"
                    v-model="state.form.mobile"
                    placeholder="请输入商家电话"
                    @input="setValue($event,'mobile')"
                  />
                </view>
              </uni-forms-item>
              <uni-forms-item
                label="客服电话"
                name="kefu_tel"
                required
              >
                <view class="form-box-input-item">
                  <input
                    :disabled="state.disabled"
                    @input="setValue($event,'kefu_tel')"
                    type="text"
                    v-model="state.form.kefu_tel"
                    placeholder="请输入客服电话"
                  />
                </view>
              </uni-forms-item>

              <!-- <uni-forms-item
                label="商户名称"
                name="merchant_name"
                required
              >
                <view class="form-box-input-item">
                  <input
                    :disabled="state.disabled"
                    type="text"
                    v-model="state.form.merchant_name"
                    placeholder="请输入商户名称"
                    @input="setValue($event,'merchant_name')"
                  />
                </view>
              </uni-forms-item> -->

            </view>
          </view>
        </view>
        <view class="content-box">
          <view class="header-title">让利选择</view>
          <view
            v-if="!state.seeAccount"
            class="bg-white"
          >
            <view class="formItem-box">
              <uni-forms-item
                label="让利比例"
                name="discount"
                required
                class="none-border"
              >
                <picker
                  @change="bindPickerChange($event,'discount')"
                  :value="state.form.discount"
                  :disabled="state.disabled"
                  :range="discountList"
                  range-key="name"
                >
                  <view class="form-box-input-item form-top-style">
                    <view
                      style="font-size:30rpx;"
                      class="text-color"
                    >{{ state.form.discount }}%</view>
                    <uni-icons
                      type="forward"
                      size="22"
                      color="#999999"
                    ></uni-icons>
                  </view>
                </picker>
              </uni-forms-item>
              <view class="footer-message">
                选择让利比例可参与平台抢红包活动
              </view>
            </view>
          </view>
        </view>
        <view class="content-box">
          <view class="header-title">营业执照信息</view>
          <view
            v-if="!state.seeAccount"
            class="bg-white"
          >
            <view class="formItem-box">

              <uni-forms-item
                label="企业证件类型"
                name="identity"
                required
              >
                <picker
                  @change="bindPickerChange($event,'identity')"
                  :value="state.form.identity"
                  :range="radioList1"
                  :disabled="state.disabled"
                  range-key="name"
                >
                  <view class="form-box-input-item form-top-style">
                    <view
                      style="font-size:30rpx;"
                      class="text-color"
                    >{{ filterText(radioList1,state.form.identity) ||'请选择企业证件类型'}}</view>
                    <uni-icons
                      type="forward"
                      size="22"
                      color="#999999"
                    ></uni-icons>
                  </view>
                </picker>
              </uni-forms-item>

              <uni-forms-item
                label=""
                name="business_license"
                class="none-border"
              >
                <view>
                  <view class="img-title">
                    <span class="color-style">*</span>营业执照照片
                  </view>
                  <view class="ss-flex justify-between">
                    <s-uploader
                      :disabled="state.disabled"
                      fileMediatype="image"
                      v-model:url="state.form.business_license"
                      :limit="1"
                      :delIcon="!state.disabled"
                      :sizeType="['original']"
                      :listStyles="{border:false}"
                      :imageStyles="{ width: '400rpx',height:'350rpx'}"
                      :isZip="true"
                    >
                      <image
                        style=" width: 400rpx;border-radius:20rpx"
                        src="https://xyh-static-app.oss-cn-hangzhou.aliyuncs.com/storage/default/20250422/16c0b9a0e9f486e6a9f9d4131967e8d5.png"
                        mode="widthFix"
                      />
                    </s-uploader>
                  </view>
                </view>
              </uni-forms-item>

              <view class="footer-message margin-top-style">建议上传图片大小不能超过1.5M</view>
              <uni-forms-item
                label="营业执照名称"
                name="company_name"
                required
              >
                <view class="form-box-input-item">
                  <input
                    :disabled="state.disabled"
                    type="text"
                    v-model="state.form.company_name"
                    placeholder="请输入营业执照名称"
                    @input="setValue($event,'company_name')"
                  />
                </view>
              </uni-forms-item>
              <uni-forms-item
                label="营业执照编号"
                name="social_credit_code"
                required
              >
                <view class="form-box-input-item">
                  <input
                    :disabled="state.disabled"
                    type="text"
                    v-model="state.form.social_credit_code"
                    placeholder="请输入营业执照编号"
                    @input="setValue($event,'social_credit_code')"
                  />
                </view>
              </uni-forms-item>
              <uni-forms-item
                label="营业执照地址"
                name="city_id"
                required
              >
                <view
                  class="form-box-input-item"
                  @click="state.disabled?null:state.showRegion=true"
                >
                  <view
                    style="font-size:30rpx;"
                    class="text-color"
                  >{{ state.address_city || '请选择营业执照地址' }}</view>
                  <uni-icons
                    type="forward"
                    size="22"
                    color="#999999"
                  ></uni-icons>
                </view>
              </uni-forms-item>
              <uni-forms-item
                label="执照有效期-起"
                name="licenseStart"
                required
              >
                <view class="form-box-input-item">
                  <uni-datetime-picker
                    type="date"
                    v-model="state.form.licenseStart"
                    :disabled="state.disabled"
                  >
                    {{state.form.licenseStart||'请选择执照有效期-起'}}
                    <uni-icons
                      type="forward"
                      size="22"
                      color="#999999"
                    ></uni-icons>
                  </uni-datetime-picker>
                </view>
              </uni-forms-item>
              <uni-forms-item
                label="执照有效期-止"
                required
                :class="[state.time2==1?'none-border':'']"
              >
                <view class="form-box-input-item">
                  <radio-group
                    @change="radioChangeTime($event,'time2')"
                    class="ss-flex flex-wrap font-1 "
                    style="width:370rpx;color:#424242"
                  >
                    <label
                      class="uni-list-cell uni-list-cell-pd ss-flex ss-m-l-10"
                      v-for="(item) in timeRadioList"
                      :key="item.value"
                    >
                      <radio
                        color="#003288"
                        :disabled="state.disabled"
                        style="transform: scale(0.5)"
                        :value="String(item.value)"
                        :checked="state.time2 == item.value"
                      />
                      <view
                        class="font-1"
                        style="color:gray"
                      >{{item.label}}</view>
                    </label>
                  </radio-group>
                </view>
              </uni-forms-item>
              <uni-forms-item
                v-if="state.time2==1"
                label=""
                name="licenseEnd"
              >
                <view class="form-box-input-item">
                  <uni-datetime-picker
                    type="date"
                    v-model="state.form.licenseEnd"
                    :disabled="state.disabled"
                  >
                    {{state.form.licenseEnd||'请选择执照有效期-止'}}
                    <uni-icons
                      type="forward"
                      size="22"
                      color="#999999"
                    ></uni-icons>
                  </uni-datetime-picker>
                </view>
              </uni-forms-item>
            </view>
          </view>
        </view>
        <view class="content-box">
          <view class="header-title">门店信息</view>
          <view
            v-if="!state.seeAccount"
            class="bg-white"
          >
            <view class="formItem-box">
              <uni-forms-item
                label="商户定位"
                name="latitude"
                required
              >
                <view
                  class="form-box-input-item"
                  @tap="choosePos"
                >
                  <view
                    style="font-size:30rpx;width:280rpx;line-height:60rpx"
                    class="ss-line-1 text-right text-color"
                  >{{ state.pos_txt || '请选择商户定位' }}</view>
                  <uni-icons
                    type="forward"
                    size="22"
                    color="#999999"
                  ></uni-icons>
                </view>
              </uni-forms-item>
              <uni-forms-item
                label="详细地址"
                name="address"
                required
              >
                <view class="form-box-input-item">
                  <input
                    :disabled="state.disabled"
                    type="text"
                    v-model="state.form.address"
                    placeholder="请输入商户位置"
                    @input="setValue($event,'address')"
                  />
                </view>
              </uni-forms-item>
              <uni-forms-item
                label="经营所在地"
                name="company_location"
                required
              >
                <view class="form-box-input-item">
                  <input
                    :disabled="state.disabled"
                    type="text"
                    v-model="state.form.company_location"
                    placeholder="请输入经营所在地"
                    @input="setValue($event,'company_location')"
                  />
                </view>
              </uni-forms-item>
            </view>
          </view>
        </view>
        <view class="content-box">
          <view class="header-title">法人信息</view>
          <view
            v-if="!state.seeAccount"
            class="bg-white"
          >
            <view class="formItem-box">
              <uni-forms-item
                label="法人证件类型"
                name="legal_id_type"
                required
              >
                <picker
                  @change="bindPickerChange($event,'legal_id_type')"
                  :value="state.form.legal_id_type"
                  :range="legalIdList"
                  :disabled="state.disabled"
                  range-key="name"
                >
                  <view class="form-box-input-item form-top-style">
                    <view
                      style="font-size:30rpx;"
                      class="text-color"
                    >{{ '身份证' }}</view>
                    <uni-icons
                      type="forward"
                      size="22"
                      color="#999999"
                    ></uni-icons>
                  </view>
                </picker>
              </uni-forms-item>
              <uni-forms-item
                name="protrait_card"
                class="none-border"
              >
                <view class="bot-solid">
                  <view class="img-title"><span class="color-style">*</span>证件照-人像面</view>
                  <view class="ss-flex justify-between">
                    <s-uploader
                      :disabled="state.disabled"
                      :delIcon="!state.disabled"
                      fileMediatype="image"
                      v-model:url="state.form.protrait_card"
                      :limit="1"
                      :sizeType="['original']"
                      :listStyles="{border:false}"
                      :imageStyles="{ width: '400rpx',height:'350rpx'}"
                      :isZip="true"
                    >
                      <image
                        style=" width: 400rpx;border-radius:20rpx"
                        src="https://xyh-static-app.oss-cn-hangzhou.aliyuncs.com/storage/default/20250509/0ecd22044961b074f6f3d672d14434f8.png"
                        mode="widthFix"
                      />
                    </s-uploader>
                  </view>
                </view>
              </uni-forms-item>
              <view class="footer-message margin-top-style">建议上传图片大小不能超过1.5M</view>
              <uni-forms-item
                name="reverse_card"
                class="none-border"
              >
                <view class="bot-solid">
                  <view class="img-title"><span class="color-style">*</span>证件照-国徽面</view>
                  <view class="ss-flex justify-between">
                    <s-uploader
                      :disabled="state.disabled"
                      :delIcon="!state.disabled"
                      fileMediatype="image"
                      v-model:url="state.form.reverse_card"
                      :limit="1"
                      :sizeType="['original']"
                      :listStyles="{border:false}"
                      :imageStyles="{ width: '400rpx',height:'350rpx'}"
                      :isZip="true"
                    >
                      <image
                        style=" width: 400rpx;border-radius:20rpx"
                        src="https://xyh-static-app.oss-cn-hangzhou.aliyuncs.com/storage/default/20250509/9ba815eef0c6f7b626d8fc315dd3a88c.png"
                        mode="widthFix"
                      />
                    </s-uploader>
                  </view>
                </view>
              </uni-forms-item>
              <view class="footer-message margin-top-style">建议上传图片大小不能超过1.5M</view>
              <uni-forms-item
                label="法人姓名"
                name="name"
                required
              >
                <view class="form-box-input-item">
                  <input
                    :disabled="state.disabled"
                    type="text"
                    v-model="state.form.name"
                    placeholder="请输入法人姓名"
                    @input="setValue($event,'name')"
                  />
                </view>
              </uni-forms-item>
              <uni-forms-item
                label="法人证件号"
                name="card_number"
                required
              >
                <view class="form-box-input-item">
                  <input
                    :disabled="state.disabled"
                    type="text"
                    v-model="state.form.card_number"
                    placeholder="请输入法人证件号"
                    @input="setValue($event,'card_number')"
                  />
                </view>
              </uni-forms-item>
              <uni-forms-item
                label="身份证有效期-起"
                name="idCardStart"
                required
              >
                <view class="form-box-input-item">
                  <uni-datetime-picker
                    :disabled="state.disabled"
                    type="date"
                    :clear-icon="false"
                    v-model="state.form.idCardStart"
                  >
                    {{state.form.idCardStart||'请选择身份证有效期-起'}}
                    <uni-icons
                      type="forward"
                      size="22"
                      color="#999999"
                    ></uni-icons>
                  </uni-datetime-picker>
                </view>
              </uni-forms-item>
              <uni-forms-item
                label="身份证有效期-止"
                required
                :class="[state.time1==1?'none-border':'']"
              >
                <view class="form-box-input-item">
                  <radio-group
                    @change="radioChangeTime($event,'time1')"
                    class="ss-flex flex-wrap font-1 ss-p-t-14"
                    style="width:370rpx;color:#424242"
                  >
                    <label
                      class="uni-list-cell uni-list-cell-pd ss-flex ss-m-l-10"
                      v-for="(item) in timeRadioList"
                      :key="item.value"
                    >
                      <radio
                        color="#003288"
                        :disabled="state.disabled"
                        style="transform: scale(0.5)"
                        :value="String(item.value)"
                        :checked="state.time1 == item.value"
                      />
                      <view
                        class="font-1"
                        style="color:gray"
                      >{{item.label}}</view>
                    </label>
                  </radio-group>

                </view>
              </uni-forms-item>
              <uni-forms-item
                v-if="state.time1==1"
                label=""
                name="idCardEnd"
              >
                <view class="form-box-input-item">
                  <uni-datetime-picker
                    type="date"
                    v-model="state.form.idCardEnd"
                    :disabled="state.disabled"
                  >
                    {{state.form.idCardEnd||'请选择身份证有效期-止'}}
                    <uni-icons
                      type="forward"
                      size="22"
                      color="#999999"
                    ></uni-icons>
                  </uni-datetime-picker>
                </view>
              </uni-forms-item>
            </view>
          </view>
        </view>
        <view class="content-box">
          <view class="header-title">证照信息</view>
          <view
            v-if="!state.seeAccount"
            class="bg-white"
          >
            <view class="formItem-box">
              <uni-forms-item name="doorPic">
                <view class="bot-solid">
                  <view class="img-title"><span class="color-style">*</span>
                    门头照
                    <span class="message-title-style">门头照片，招牌文字清晰可见</span>
                  </view>
                  <view class="ss-flex justify-between">
                    <s-uploader
                      :disabled="state.disabled"
                      :delIcon="!state.disabled"
                      fileMediatype="image"
                      v-model:url="state.form.doorPic"
                      :limit="1"
                      :sizeType="['original']"
                      :listStyles="{border:false}"
                      :imageStyles="{ width: '400rpx',height:'350rpx'}"
                      :isZip="true"
                    >
                      <image
                        style=" width: 400rpx;border-radius:20rpx"
                        src="https://xyh-static-app.oss-cn-hangzhou.aliyuncs.com/storage/default/20250422/f2a3dabbc5b7b4a609b0c06742f83a3a.png"
                        mode="widthFix"
                      />
                    </s-uploader>
                  </view>
                </view>
              </uni-forms-item>
              <uni-forms-item name="cashierDeskPic">
                <view class="bot-solid">
                  <view class="img-title"><span class="color-style">*</span>收银台照
                    <span class="message-title-style">支付场景中的支付机具或扫码枪</span>
                  </view>
                  <view class="ss-flex justify-between">
                    <s-uploader
                      :disabled="state.disabled"
                      :delIcon="!state.disabled"
                      fileMediatype="image"
                      v-model:url="state.form.cashierDeskPic"
                      :limit="1"
                      :sizeType="['original']"
                      :listStyles="{border:false}"
                      :imageStyles="{ width: '400rpx',height:'350rpx'}"
                      :isZip="true"
                    >
                      <image
                        style=" width: 400rpx;border-radius:20rpx"
                        src="https://xyh-static-app.oss-cn-hangzhou.aliyuncs.com/storage/default/20250422/aecb39d4cacbd0f9eb729ae892cf9143.png"
                        mode="widthFix"
                      />
                    </s-uploader>
                  </view>
                </view>
              </uni-forms-item>
              <uni-forms-item name="insidePic">
                <view class="bot-solid">
                  <view class="img-title"><span class="color-style">*</span>经营场所照
                    <span class="message-title-style">店内照，请勿拍摄单一物品</span>
                  </view>
                  <view class="ss-flex justify-between">
                    <s-uploader
                      :disabled="state.disabled"
                      :delIcon="!state.disabled"
                      fileMediatype="image"
                      v-model:url="state.form.insidePic"
                      :limit="1"
                      :sizeType="['original']"
                      :listStyles="{border:false}"
                      :imageStyles="{ width: '400rpx',height:'350rpx'}"
                      :isZip="true"
                    >
                      <image
                        style=" width: 400rpx;border-radius:20rpx"
                        src="https://xyh-static-app.oss-cn-hangzhou.aliyuncs.com/storage/default/20250422/e1e26270bb089cb73f24680d15fc97ac.png"
                        mode="widthFix"
                      />
                    </s-uploader>
                  </view>
                </view>
              </uni-forms-item>
              <uni-forms-item>
                <view class="bot-solid">
                  <view class="img-title">其它</view>
                  <view class="ss-flex justify-between">
                    <s-uploader
                      :disabled="state.disabled"
                      :delIcon="!state.disabled"
                      fileMediatype="image"
                      v-model:url="state.form.other_img"
                      :limit="6"
                      :sizeType="['original']"
                      :listStyles="{border:false}"
                      :imageStyles="{ width: '400rpx',height:'350rpx'}"
                      :isZip="true"
                    >
                      <image
                        style=" width: 400rpx;border-radius:20rpx"
                        src="https://xyh-static-app.oss-cn-hangzhou.aliyuncs.com/storage/default/20250422/0e36667057e9f0548885fca80339d4d5.png"
                        mode="widthFix"
                      />
                    </s-uploader>
                  </view>
                </view>
              </uni-forms-item>
            </view>
          </view>
        </view>
        <view class="content-box">
          <view class="header-title">结算信息</view>
          <view
            v-if="!state.seeAccount"
            class="bg-white"
          >
            <view class="formItem-box">
              <uni-forms-item
                label="结算对象"
                name="bank_type"
                required
              >
                <picker
                  @change="bindPickerChange($event,'bank_type')"
                  :value="state.form.bank_type"
                  :range="radioList2"
                  :disabled="state.disabled"
                  range-key="name"
                >
                  <view class="form-box-input-item form-top-style">
                    <view
                      style="font-size:30rpx;"
                      class="text-color"
                    >{{ filterText(radioList2,state.form.bank_type)||'请选择结算对象' }}</view>
                    <uni-icons
                      type="forward"
                      size="22"
                      color="#999999"
                    ></uni-icons>
                  </view>
                </picker>
              </uni-forms-item>
              <uni-forms-item name="bank_card_image">
                <view class="bot-solid">
                  <view class="img-title"><span class="color-style">*</span>银行卡/开户证明
                    <span class="message-title-style">银行卡拍照/对公开户证明拍照</span>
                  </view>
                  <view class="ss-flex justify-between">
                    <s-uploader
                      :disabled="state.disabled"
                      :delIcon="!state.disabled"
                      fileMediatype="image"
                      v-model:url="state.form.bank_card_image"
                      :limit="1"
                      :sizeType="['original']"
                      :listStyles="{border:false}"
                      :imageStyles="{ width: '400rpx',height:'350rpx'}"
                      :isZip="true"
                    >
                      <image
                        style=" width: 400rpx;border-radius:20rpx"
                        src="https://xyh-static-app.oss-cn-hangzhou.aliyuncs.com/storage/default/20250509/04bd5948e676388a7821216dbd76914f.png"
                        mode="widthFix"
                      />
                    </s-uploader>
                  </view>
                </view>
              </uni-forms-item>
              <uni-forms-item
                label="开户名"
                name="bank_receive_name"
                required
                class="none-border"
              >
                <view class="form-box-input-item">
                  <input
                    :disabled="state.disabled"
                    type="text"
                    v-model="state.form.bank_receive_name"
                    placeholder="请输入开户名"
                    @input="setValue($event,'bank_receive_name')"
                  />
                </view>
              </uni-forms-item>
              <view class="footer-message">
                对公填写企业名称/对私填写法人名称
              </view>
              <uni-forms-item
                label="开户账号"
                name="bank_account"
                required
              >
                <view class="form-box-input-item">
                  <input
                    :disabled="state.disabled"
                    type="text"
                    v-model="state.form.bank_account"
                    placeholder="请输入开户账号"
                    @input="setValue($event,'bank_account')"
                  />
                </view>
              </uni-forms-item>
              <uni-forms-item
                label="预留手机号"
                name="bank_mobile"
                required
              >
                <view class="form-box-input-item">
                  <input
                    :disabled="state.disabled"
                    type="text"
                    v-model="state.form.bank_mobile"
                    placeholder="请输入预留手机号"
                    @input="setValue($event,'bank_mobile')"
                  />
                </view>
              </uni-forms-item>
              <uni-forms-item
                label="开户行"
                name="bankName"
                required
              >
                <view class="form-box-input-item">
                  <view
                    class="form-item ss-flex justify-between align-center b-b-c"
                    @tap="state.disabled?null:state.showBank = true"
                  >
                    <view class="uni-input text-color">{{ state.form.bankName || '请选择开户行' }}</view>
                  </view>
                </view>
              </uni-forms-item>
              <uni-forms-item
                label="银行网点"
                name="bank_name"
                required
              >
                <view class="form-box-input-item">
                  <view
                    class="form-item ss-flex justify-between align-center b-b-c"
                    @tap="state.disabled?null:state.showBranchBank = true"
                  >
                    <view class="uni-input text-color">{{ state.form.bank_name || '请选择银行网点' }}</view>
                  </view>
                </view>
              </uni-forms-item>
              <uni-forms-item
                label="银行网点编码"
                name="bank_code"
                required
              >
                <view class="form-box-input-item">
                  <input
                    class="form-input"
                    :disabled="state.disabled"
                    v-model="state.form.bank_code"
                    placeholder="请选择收款银行后回填"
                    placeholder-class="placeholder-class"
                  />
                </view>
              </uni-forms-item>
            </view>
          </view>
        </view>
        <!-- <view class="content-box">
          <view class="header-title">收款账户</view>
          <view
            v-if="!state.seeAccount"
            class="bg-white"
          >
            <view class="formItem-box">

              <uni-forms-item
                label="银行卡类型"
                name="serve"
                required
              >
                <view class="form-box-input-item">
                  <radio-group
                    @change="bankTypeChange"
                    class="ss-flex flex-wrap font-1 ss-p-t-14 radio-box"
                    style="width:370rpx;color:#424242"
                  >
                    <label
                      class="uni-list-cell uni-list-cell-pd ss-flex ss-m-l-10"
                      v-for="(item) in radioList2"
                      :key="item.value"
                    >
                      <radio
                        color="#003288"
                        style="transform: scale(0.5)"
                        :value="item.value"
                        :disabled="state.disabled"
                        :checked="state.form.bank_type == item.value"
                      />
                      <view
                        class="font-1"
                        style="color:gray"
                      >{{item.label}}</view>
                    </label>
                  </radio-group>
                </view>
              </uni-forms-item>

            </view>
          </view>
        </view> -->
        <!-- <view class="content-box">
          <view class="header-title">经营信息</view>
          <view
            v-if="!state.seeAccount"
            class="bg-white"
          >
            <view class="formItem-box">

            </view>
          </view>
        </view> -->

        <template v-if="state.seeAccount">
          <!-- 商家账号信息 -->
          <view
            class="ss-m-t-20 bg-white"
            style="padding:33rpx 26rpx 34rpx 37rpx;border-radius: 20rpx;"
          >
            <view class="form-box-head-title ss-m-b-24">商家账号信息</view>
            <view style="line-height:1.5em;color: #383838;">
              <view>账号：{{state.accountInfo.account}}</view>
              <view>密码：{{state.accountInfo.password}}</view>
              <view>系统地址：{{state.accountInfo.website}}</view>
            </view>
            <view class="ss-flex justify-end">
              <button
                class="btn2 ss-reset-button "
                @tap="onCopy"
              >
                复制
              </button>
            </view>
          </view>

          <!-- 支付码 -->
          <view
            v-if="state.accountInfo.pay_qrcode"
            class="ss-m-t-20 bg-white"
            style="padding:33rpx 26rpx 34rpx 37rpx;border-radius: 20rpx;"
          >
            <view class="form-box-head-title ss-m-b-24">支付码</view>
            <image
              class="ss-flex justify-center"
              style=" width: 300rpx;height:300rpx;margin:0 auto"
              :src="sheep.$url.cdn(state.accountInfo.pay_qrcode)"
            />
            <view class="ss-flex justify-end">
              <button
                class="btn2 ss-reset-button "
                @tap="handleSave(sheep.$url.cdn(state.accountInfo.pay_qrcode))"
              >
                下载
              </button>
            </view>
          </view>
        </template>

        <view style="height:300rpx"></view>
      </uni-forms>
    </view>
    <!-- 底部按钮 -->
    <view
      class="bottom-box ss-safe-bottom"
      v-if="state.form.id == null"
    >
      <view class="ss-p-y-20 ss-flex justify-center">
        <button
          class="btn-box"
          @click="submit"
        >提交</button>
      </view>
    </view>
    <view
      class="bottom-box ss-safe-bottom"
      v-if="(state.form.sigin_link != null && state.status === 0) "
    >
      <view class="ss-p-y-20 ss-flex justify-center">
        <view
          class="btn-box"
          @click="towebview"
        >去签约</view>
      </view>
    </view>

    <view
      class="bottom-box ss-safe-bottom"
      v-if="state.form.status  == 2"
    >
      <view class="ss-p-y-20 ss-flex justify-center">
        <view
          class="btn-box"
          :disabled="true"
          @click="submit"
        >重新提交</view>
      </view>
    </view>

    <!-- </su-fixed> -->
    <!-- 地址选择弹窗 -->
    <su-region-picker
      :show="state.showRegion"
      @cancel="state.showRegion = false"
      @confirm="onRegionConfirm"
    />
    <category-picker
      :show="state.showType"
      @cancel="state.showType = false"
      @confirm="bindPickerChange($event,'type')"
    />
    <!-- 选择银行 -->
    <openingBank
      :show="state.showBank"
      @cancel="state.showBank = false"
      @confirm="bindPickerChange($event,'openingBank')"
    >
    </openingBank>
    <!-- 选择银行支行 -->
    <subBranch
      :fin_institution_code="state.form.fin_institution_code"
      :show="state.showBranchBank"
      @cancel="state.showBranchBank = false"
      @confirm="bindPickerChange($event,'subBranch')"
    >
    </subBranch>
    <!-- mcc行业类型 -->
    <mcc-picker
      :show="state.showMcc"
      @cancel="state.showMcc = false"
      @confirm="bindPickerChange($event,'mcc')"
    >
    </mcc-picker>
    <!-- 签约 -->
    <surprise-code
      v-if="state.showSignCode"
      @cancel="state.showSignCode = false"
      :show="state.showSignCode"
      :jjId="state.jjId"
      :merchantNo="state.form.merchant_no"
    >
    </surprise-code>
  </s-layout>
</template>

<script setup>
import assNavbar from '@/components/ass-navbar.vue';
import categoryPicker from '@/ygb/pages/commission/components/category-picker.vue';
import $store from '@/sheep/store';
import {
  onLoad,
  onShow,
  onUnload
} from '@dcloudio/uni-app';
import Test from "@/sheep/helper/test.js";
import commissionAPI from "@/ygb/api/commission"
import {
  showAuthModal,
} from '@/sheep/hooks/useModal';
import {
  ref,
  computed,
  reactive,
  watch,
  nextTick
} from 'vue';
import sheep from '@/sheep';
import { clone } from 'lodash'
import bankPicker from '../components/bank-picker'
import openingBank from '../components/openingBank'
import subBranch from '../components/subBranch'
import mccPicker from '../components/mcc-picker'
import surpriseCode from "@/ygb/pages/commission/components/surprise-code.vue"
const radioList = [
  { value: 2, label: '本地生活' },
  { value: 1, label: '电商商家' },
  { value: 3, label: '鲸喜生活圈' },
];


const radioFormList = computed(() => {
  if (state.form.serve == 1) {
    return [{ value: 1, label: '电商商家' }];
  } else if (state.form.serve == 2) {
    return [{ value: 2, label: '本地生活' }];
  } else if (state.form.serve == 3) {
    return [{ value: 3, label: '鲸喜生活圈' }];
  } else {
    return [{ value: 3, label: '鲸喜生活圈' }];
  }
});

const edited = computed(() => {
  return state.form.serve ? false : true;
})

const form = ref(null);


// 数据
const state = reactive({
  discountIndex: 0,
  showType: false,
  type: 0,//0商家自己入驻   1代理帮商家入驻
  showRegion: false,
  jjId: '',
  showSignCode: false,
  form: {
    id: null,
    serve: '',//商户类型
    name: '',// 商户姓名
    mobile: '',//  商户手机号
    merchant_name: '',// 商户名称
    company_name: '', // 企业名称
    social_credit_code: '',// 社会信用代码
    store_category_id: null,// 商户类型
    // 地址选择
    province: null,//省
    district: null,//市
    city: null,//区
    province_id: null,//省id
    district_id: null,//市id
    city_id: '', // 所在城市
    latitude: '', // 经度
    longitude: '', // 纬度
    address: '', // 详细地址
    discount: 0, // 让利比例
    bank_name: '',  // 收款银行
    bank_receive_name: '',  // 收款户名
    bank_account: '',   // 收款账号
    bank_mobile: '',  // 预留手机号
    company_location: '',   // 经营所在地
    business_license: '',   // 营业执照
    protrait_card: '',   // 身份证人像照
    reverse_card: '',   // 身份证国徽照
    bank_card_image: '',   // 账户证明
    cashierDeskPic: '',   // 收银台
    doorPic: '',   // 门头照
    insidePic: '',   // 经营环境
    other_img: '',   // 其他
    bank_type: null,//银行卡类型
    is_bd: 0,
    // 银行名称
    bank_name: '',
    // 银行编码
    bank_code: '',
    // 身份证
    card_number: '',
    // mcc
    mcc_code: '',
    // 身份证有效期起
    idCardStart: '',
    // 身份证有效期至
    idCardEnd: '',
    // 营业执照
    licenseStart: '',
    licenseEnd: '',
    identity: null,//商户类型
    province_city_area: '',
    kefu_tel: '',//客服电话
    legal_id_type: 'id_card',
    fin_institution_code: '',
    bankName: '',

  },
  shop_type_txt: '',//商户类型
  address_city: '',//城市
  pos_txt: '',//定位点
  disabled: false,
  userInfo: {},
  seeAccount: false,//是否是查看账号
  accountInfo: {},//账号信息
  image1: '',
  image2: '',
  image3: '',
  image_more: '',
  bd_no: '',
  time1: 1,
  time2: 1,
  mcc_name: '',
  status: null,
  headerStatus: null,
  submitBtnShow: false,
  rz_id: null,
  showBank: false,
  showBranchBank: false
});


watch(
  () => state.form,
  (newVal, oldVal) => {
    nextTick(() => {
      if (!state.rz_id) {
        uni.setStorageSync('applyFormDataStorage', JSON.stringify(newVal))
      }
    })
  },
  { deep: true } // 启用深度监听
);
let headerObj = reactive({
  agreement: 0,
  real_name: 0,
  elec: 0,
})
const DEFAULT_LOCATION = {
  latitude: 30.308041, // 默认坐标
  longitude: 120.372893,
  city_name: "杭州市",
};
const discountList = [
  { name: '0%', value: 0 },
  { name: '15%', value: 15 },
  { name: '20%', value: 20 },
]
const timeRadioList = [
  { value: 1, label: '选择日期' },
  { value: 2, label: '永久有效' },
];
const radioList1 = [
  { value: 1, name: '企业商户' },
  { value: 2, name: '个体商户' },

]
const radioList2 = [
  { value: 1, name: '对公户' },
  { value: 2, name: '银行卡' },
]
const legalIdList = [
  { value: 'id_card', name: '身份证' },
]

function inputNumber (e) {
  if (Number(e.detail.value) > 20) {
    uni.showToast({
      title: '让利比例不能超过20%',
      icon: 'none'
    })
    setTimeout(() => {
      state.form.discount = 20
    }, 50)
  }
}
// 复制
const onCopy = () => {
  sheep.$helper.copyText(
    `账号：${state.accountInfo.account};密码：${state.accountInfo.password};系统地址：${state.accountInfo.website}`
  );
};

const rules = {
  //商户姓名
  name: { rules: [{ required: true, errorMessage: '请填写姓名', }] },
  //  商户手机号
  mobile: {
    rules: [{
      required: true,
      errorMessage: '请输入商家联系电话',
    }, {
      validateFunction: (rule, value, data, callback) => {
        // 异步需要返回 Promise 对象
        return new Promise((resolve, reject) => {
          if (Test.mobile(value)) {
            resolve()
          } else {
            reject(new Error('联系电话格式错误'))
          }
        })
      }
    }]
  },
  // 商户名称
  merchant_name: { rules: [{ required: true, errorMessage: '请填写商户简称', }] },
  // 企业名称
  company_name: { rules: [{ required: true, errorMessage: '请填写营业执照名称', }] },
  // 社会信用代码
  social_credit_code: { rules: [{ required: true, errorMessage: '请填写营业执照编号', }] },
  // 商户类型
  store_category_id: { rules: [{ required: true, errorMessage: '请选择平台类目', }] },
  // 所在城市
  city_id: { rules: [{ required: true, errorMessage: '请选择城市', }] },
  // 商户定位
  latitude: { rules: [{ required: true, errorMessage: '请选择定位', }] },
  // 详细地址
  address: { rules: [{ required: true, errorMessage: '请填写商户地址', }] },
  // 让利比例
  discount: { rules: [{ required: true, errorMessage: '请选择让利比例', }] },
  // 收款银行
  bankName: { rules: [{ required: true, errorMessage: '请选择开户行', }] },
  // 收款户名
  bank_receive_name: { rules: [{ required: true, errorMessage: '请输入开户名', }] },
  // 收款账号
  bank_account: { rules: [{ required: true, errorMessage: '请输入开户账号', }] },
  // 预留手机号
  bank_mobile: {
    rules: [{ required: true, errorMessage: '请输入预留手机号' }, {
      validateFunction: (rule, value, data, callback) => {
        // 异步需要返回 Promise 对象
        return new Promise((resolve, reject) => {
          if (Test.mobile(value)) {
            resolve()
          } else {
            reject(new Error('预留手机号格式错误'))
          }
        })
      }
    }]
  },
  // 经营所在地
  company_location: { rules: [{ required: true, errorMessage: '请输入经营所在地', }] },
  // 营业执照
  business_license: {
    rules: [{
      validateFunction: (rule, value, data, callback) => {
        // 异步需要返回 Promise 对象
        return new Promise((resolve, reject) => {
          if (state.form.business_license) {
            resolve()
          } else {
            reject(new Error('请上传营业执照'))
          }
        })
      }
    }]
  },
  // 身份证人像照
  protrait_card: {
    rules: [{
      validateFunction: (rule, value, data, callback) => {
        // 异步需要返回 Promise 对象
        return new Promise((resolve, reject) => {
          if (state.form.protrait_card) {
            resolve()
          } else {
            reject(new Error('请上传身份证人像照'))
          }
        })
      }
    }]
  },
  // 身份证国徽照
  reverse_card: {
    rules: [{
      validateFunction: (rule, value, data, callback) => {
        // 异步需要返回 Promise 对象
        return new Promise((resolve, reject) => {
          if (state.form.reverse_card) {
            resolve()
          } else {
            reject(new Error('请上传身份证国徽照'))
          }
        })
      }
    }]
  },
  // 账户证明
  bank_card_image: {
    rules: [{
      validateFunction: (rule, value, data, callback) => {
        // 异步需要返回 Promise 对象
        return new Promise((resolve, reject) => {
          if (state.form.bank_card_image) {
            resolve()
          } else {
            reject(new Error('请上传账户证明'))
          }
        })
      }
    }]
  },
  // 收银台
  cashierDeskPic: {
    rules: [{
      validateFunction: (rule, value, data, callback) => {
        // 异步需要返回 Promise 对象
        return new Promise((resolve, reject) => {
          if (state.form.cashierDeskPic) {
            resolve()
          } else {
            reject(new Error('请上传收银台照片'))
          }
        })
      }
    }]
  },
  // 门头照
  doorPic: {
    rules: [{
      validateFunction: (rule, value, data, callback) => {
        // 异步需要返回 Promise 对象
        return new Promise((resolve, reject) => {
          if (state.form.doorPic) {
            resolve()
          } else {
            reject(new Error('请上传门头照'))
          }
        })
      }
    }]
  },
  // 经营环境
  insidePic: {
    rules: [{
      validateFunction: (rule, value, data, callback) => {
        // 异步需要返回 Promise 对象
        return new Promise((resolve, reject) => {
          if (state.form.insidePic) {
            resolve()
          } else {
            reject(new Error('请上传经营环境照片'))
          }
        })
      }
    }]
  },
  // 其他
  other_img: { rules: [{ required: true, errorMessage: '请上传其它', }] },
  // 银行卡类型
  bank_type: { rules: [{ required: true, errorMessage: '请选择结算对象', }] },
  // 银行名称
  bank_name: {
    rules: [{ required: true, errorMessage: '请选择银行网点', }, {
      validateFunction: (rule, value, data, callback) => {
        // 异步需要返回 Promise 对象
        return new Promise((resolve, reject) => {
          if (state.form.bank_name) {
            resolve()
          } else {
            reject(new Error('请选择银行网点'))
          }
        })
      }
    }]
  },
  //银行编码
  bank_code: {
    rules: [{ required: true, errorMessage: '请选择银行', }, {
      validateFunction: (rule, value, data, callback) => {
        // 异步需要返回 Promise 对象
        return new Promise((resolve, reject) => {
          if (state.form.bank_code) {
            resolve()
          } else {
            reject(new Error('请选择银行网点'))
          }
        })
      }
    }]
  },
  // 身份证
  card_number: {
    rules: [{ required: true, errorMessage: '请输入身份证', }, {
      validateFunction: (rule, value, data, callback) => {
        // 异步需要返回 Promise 对象
        return new Promise((resolve, reject) => {
          if (Test.idCard(value)) {
            resolve()
          } else {
            reject(new Error('身份证格式错误'))
          }
        })
      }
    }]
  },
  idCardStart: { rules: [{ required: true, errorMessage: '请选择身份证有效期', }] },
  idCardEnd: {
    rules: [{ required: true, errorMessage: '请选择身份证有效期', }, {
      validateFunction: (rule, value, data, callback) => {
        // 异步需要返回 Promise 对象
        return new Promise((resolve, reject) => {
          if (state.time1 == 1) {
            if (!state.form.idCardEnd) {
              reject(new Error('请选择有效期'))
            } else {
              resolve()
            }
          } else {
            resolve()
          }
        })
      }
    }]
  },

  // 客服电话
  kefu_tel: { rules: [{ required: true, errorMessage: '请输入客服电话' }] },
  // 身份
  identity: { rules: [{ required: true, errorMessage: '请选择商户身份类型', }] },
  // mcc行业类型
  mcc_code: { rules: [{ required: true, errorMessage: '请选择MCC行业类型', }] },
  // 营业执照有效期起
  licenseStart: { rules: [{ required: true, errorMessage: '请选择有效期', }] },
  // 营业执照有效期止
  licenseEnd: {
    rules: [{ required: true, errorMessage: '请选择有效期', }, {
      validateFunction: (rule, value, data, callback) => {
        // 异步需要返回 Promise 对象
        return new Promise((resolve, reject) => {
          if (state.time2 == 1) {
            if (!state.form.licenseEnd) {
              reject(new Error('请选择有效期'))
            } else {
              resolve()
            }
          } else {
            resolve()
          }

        })
      }
    }]
  },
}
// 选择银行卡类型
const bankTypeChange = (e) => {
  state.form.bank_type = e.detail.value
}
const filterText = (list, val) => {
  const foundItem = list.find(item => item.value == val);
  return foundItem ? foundItem.name : null;
}

// 地图位置选择
const onRegionConfirm = (e) => {
  console.log(e);

  state.address_city = e.province_name + '/' + e.city_name + '/' + e.district_name
  state.form.city_id = e.city_id
  state.form.district_id = e.district_id
  state.form.province_id = e.province_id
  state.form.city = e.city_name
  state.form.district = e.district_name
  state.form.province = e.province_name


  state.showRegion = false;
};


// 选择分类
const bindPickerChange = (e, str) => {
  if (str == 'type') {//选择商户分类
    state.form.store_category_id = e.value;
    state.shop_type_txt = e.label;
    state.showType = false;
  } else if (str == 'discount') {//选择让利比例
    // state.discountIndex = e.detail.value
    state.form.discount = discountList[e.detail.value].value
  } else if (str == 'identity') {
    // state.discountIndex = e.detail.value
    state.form.identity = radioList1[e.detail.value].value
  } else if (str == 'legal_id_type') {
    state.form.legal_id_type = legalIdList[0].value
  } else if (str == 'bank_type') {
    state.form.bank_type = radioList2[e.detail.value].value
  } else if (str == 'mcc') {
    state.form.mcc_code = e.value;
    state.mcc_name = e.label;
    state.showMcc = false;
  } else if (str == 'openingBank') {
    state.form.fin_institution_code = e.value;
    state.form.bankName = e.label;
    state.showBank = false;
    state.form.bank_code = null;
    state.form.bank_name = null;
  } else if (str == 'subBranch') {
    state.form.bank_code = e.value;
    state.form.bank_name = e.label;
    state.showBranchBank = false;
  }


};
function radioChangeTime (e, str) {
  if (str == 'time1') {
    if (e.detail.value == 2) {
      state.form.idCardEnd = '长期'
    } else {
      state.form.idCardEnd = null
    }
  }
  if (str == 'time2') {
    if (e.detail.value == 2) {
      state.form.licenseEnd = '长期'
    } else {
      state.form.licenseEnd = null
    }
  }
  state[str] = e.detail.value
}
function radioChange (e, str) {
  state.form[str] = e.detail.value
}
async function getInfo (writeType) {
  const res = await commissionAPI.giveaway.getUserInfo()//成为bd后填写资料时的信息
  state.form.agency_name = res.data?.name
  state.form.agency_mobile = res.data?.phone
  if (!res.data && writeType) {
    var userInfo = sheep.$store('user').userInfo
    state.form.agency_name = userInfo?.nickname
    state.form.agency_mobile = userInfo?.mobile
  }
  // state.form.role = sheep.$store('user').userInfo.role;
}

const handleSave = (url) => {
  if (['WechatOfficialAccount', 'H5'].includes(sheep.$platform.name)) {
    sheep.$helper.toast('请长按图片保存');
    return;
  }
  uni.downloadFile({
    url: url,
    success: (sres) => {
      console.log(sres);
      uni.saveImageToPhotosAlbum({
        filePath: sres.tempFilePath,
        success: (res) => {
          sheep.$helper.toast('保存成功');
        },
        fail: (err) => {
          sheep.$helper.toast('保存失败');
          console.log('图片保存失败:', err);
        },
      });
    }

  }).onProgressUpdate((res) => {
    uni.showLoading({
      title: '正在保存...'
    })
    if (res.progress == 100) {
      uni.hideLoading()
    }
  })
};


const submit = () => {
  const formSubmit = clone(state.form)
  formSubmit.bank_info = {
    bankName: formSubmit.bankName,
    fin_institution_code: formSubmit.fin_institution_code,
  }
  form.value.validate().then(async formVal => {
    if (state.submitBtnShow) {
      return
    }
    state.submitBtnShow = true
    uni.showLoading({
      title: '正在提交...'
    })
    state.form.province_city_area = state.form.province_id + '-' + state.form.city_id + '-' + state.form.district_id
    if (state.time1 == 2) {
      formSubmit.idCardEnd = '长期'
    }
    if (state.time2 == 2) {
      formSubmit.licenseEnd = '长期'
    }
    if (formSubmit.other_img == '') {
      formSubmit.other_img = []
    }

    const res = state.form.id
      ? await commissionAPI.merchant.applyEditNew({//有id则编辑
        ...formSubmit,
      })
      : await commissionAPI.merchant.applyAddNew({
        ...formSubmit,
      })
    uni.hideLoading();
    if (res.error == 0) {
      uni.redirectTo({
        url: `/pages/commission/merchant/submit-log?type=${state.type}`
      })
      // 清空提交缓存
      uni.removeStorageSync('applyFormDataStorage')
    } else {
      uni.showToast({
        title: res.msg,
        icon: 'none',
        duration: 3000
      })
    }
    state.submitBtnShow = false;
  }).catch(err => {
    console.log('查看校验', err);

    if (err.length) {
      uni.showToast({
        title: err[0].errorMessage,
        icon: 'none',
        duration: 3000
      })
    }
  })
}
const towebview = () => {
  uni.navigateTo({
    url: '/pages/commission/merchant/webview?url=' + state.form.sigin_link,
  });
};
const getDefaultInfo = async () => {//获取默认营业执照图等
  const res = await commissionAPI.getDefaultImg()
  state.form.business_license = res.data.business_license
  state.image1 = res.data.img1
  state.image2 = res.data.img2
  state.image3 = res.data.img3
  state.image4 = res.data.img4

}

const resolutionParameters = (data) => {
  if (data.province && data.district && data.city) {
    state.address_city = data.province + '/' + data.city + '/' + data.district
  }
  if (data.idCardEnd == '长期') {
    state.time1 = 2
    data.idCardEnd = '长期'
  }
  if (data.licenseEnd == '长期') {
    state.time2 = 2
    data.licenseEnd = '长期'
  }
  if (data.bank_info) {
    state.form.fin_institution_code = data.bank_info.fin_institution_code
    state.form.bankName = data.bank_info.bankName
  }
  if (data.mcc_code) {
    getMccList3(data.mcc_code)
  }
  if (data.latitude && data.longitude) {
    state.pos_txt = data.address
  }

  // if (data.address) {
  //   state.pos_txt = data.address
  // }
  if (data.store_category_id) {
    getTypeName(data.store_category_id)
  }
}
async function getDetail (id, is_db, type = 1) {
  const { error, data } = await commissionAPI.merchant.applyDetailTest(id, { type, is_bd: is_db });
  state.form = { ...state.form, ...data }
  console.log(state.form);
  state.status = data.status;
  state.jjId = data.id;
  if (data.status == 0 || data.status == 1) {
    state.disabled = true
  }
  if (data.address) {
    state.pos_txt = data.address
  }
  if (!data.other_img) {
    state.form.other_img = ''
  }

  resolutionParameters(state.form)
  if (data.agreement && data.real_name && data.elec) {
    headerObj = {
      agreement: data.agreement,
      real_name: data.real_name,
      elec: data.elec,
    }
  }


}
const getMccList3 = async (mccCode) => {
  const res = await commissionAPI.merchant.mccList({
    mccCode
  })
  state.mcc_name = res.data[0].mccText
}

const getTypeName = async (id) => {
  const res = await commissionAPI.merchant.storeTypeName({
    id,
  })
  state.shop_type_txt = res.data.name

}
// 获取当前账号的身份
async function isMaker (mobile) {
  const res = await commissionAPI.merchant.getUserRoleByMobile(mobile)
  if (res.error == 0) {
    state.role = res.data.max_role
  }
}
onLoad(async (option) => {
  state.userInfo = sheep.$store('user').userInfo
  // 先赋值id  如果有 表单变动就不缓存数据
  if (option.rz_id) {
    state.rz_id = option.rz_id
  }
  // NFC卡进入
  if (option.bd_no) {//刷卡滴过来  只用于鲸囍入驻
    state.bd_no = option.bd_no
    state.type = 0//自己入驻
    state.form.serve = 3
    var isLogin = $store('user').isLogin
    if (!$store('user').isLogin) {//如果未登录
      showAuthModal();
    } else {//如果已经登录，则去判断是绑卡，还是绑上下级入驻
      await isMaker(sheep.$store('user').userInfo.mobile)
      await card_is_bind(option.bd_no)
    }
    state.form.mobile = state.userInfo.mobile
    return
  }


  state.seeAccount = option.seeAccount
  if (state.seeAccount) {//seeAccount  判断是否为查看账号密码
    state.accountInfo = JSON.parse(option.account)
    console.log('state.accountInfo', state.accountInfo)
  } else {//填写表单
    await isMaker(state.userInfo.mobile)
    state.type = option.type//0商户自己入驻  1代理商入驻
    state.form.serve = option.shopType
    state.form.is_bd = option.type == '0' ? 0 : state.role == 'user' ? 0 : 1;
    if (option.type == 1) {
      myUserInfo()//bd替别人入驻  填入自己的信息
      // getInfo(option.writeType)//writeType=invite转发微信
    } else if (option.type == 0) {//自己入驻填入该账号的手机号
      state.form.mobile = state.userInfo.mobile
    }
  }
  // 只有入驻进入时调用
  if (option.rz_id) {
    await getDetail(option.rz_id, option.is_db, 2)
  } else {
    isMaker(state.userInfo.mobile)
    formFun(option)
  }



  //填写手机号获取信息进入
  if (option.inviteInfo && !state.form.agency_mobile) {
    var info = JSON.parse(option.inviteInfo)
    state.form.agency_name = info?.nickname
    state.form.agency_mobile = info?.mobile
  }


})
const formFun = (option) => {
  // 如果不是查看详情  就赋值本地数据
  let strogeFormData = uni.getStorageSync('applyFormDataStorage')
  if (strogeFormData) {
    const formDataStorage = JSON.parse(strogeFormData)
    state.form = { ...state.form, ...formDataStorage }
    console.log(state.form);


    if (state.form.status) {
      state.form.status = null
    }
    if (state.form.id) {
      state.form.id = null
    }
    state.type = option.type//0商户自己入驻  1代理商入驻
    state.form.serve = option.shopType
    state.form.is_bd = option.type == '0' ? 0 : state.role == 'user' ? 0 : 1;
    if (state.form.is_bd == 0) {
      state.form.mobile = state.userInfo.mobile
    }
    resolutionParameters(state.form)
  }
}
function signCode (item) {
  state.showSignCode = true
}
// 查询卡是否已绑定-----判断是bd还是商家
async function card_is_bind (bd_no) {
  const res = await commissionAPI.merchant.card_is_bind(bd_no)
  if (res.error == 0) {
    uni.hideLoading()
    if (res.data.available == 1) {//卡片未绑定
      if (state.role === 'user') {//---------商户
        uni.showModal({
          title: '提示',
          content: '卡片无效',
          showCancel: false,
          success: function (res) {
            if (res.confirm) {
              console.log('用户点击确定');
            }
          }
        });
        await writeInfo()//卡未绑定，查询该用户信息并填入
        return
      } else {//-----------------------------------------------bd

        if (state.userInfo.extend.extend_code) {
          uni.showModal({
            title: '提示',
            content: '不能重复绑定',
            confirmText: '返回首页',
            showCancel: false,
            success: function (res) {
              if (res.confirm) {
                console.log('用户点击确定');
                uni.reLaunch({
                  url: '/pages/index/home'
                })
              }
            }
          });
          return
        }

        uni.showModal({
          title: '提示',
          content: '是否要绑定当前卡片',
          success: async function (res) {
            if (res.confirm) {
              await card_bind(bd_no)
            }
          }
        });
      }

    } else if (res.data.available == 0) {//卡已绑定-则去绑定上下级关系------下级用
      if (state.role === 'user') {//---------商户
        console.log('+++++++++++++商户绑定上下级关系')
        await bindParent(bd_no)
        return
      } else {
        console.log('+++++++++++++当前卡片已被绑定')
        uni.showModal({
          title: 'BD邀请入驻',
          content: `当前卡片已被BD${res.data.mobile}绑定，BD不能邀请BD入驻`,
          confirmText: '返回首页',

          showCancel: false,
          success: function (res) {
            if (res.confirm) {
              console.log('用户点击确定');
              uni.reLaunch({
                url: '/pages/index/home'
              })
            }
          }
        });
        return
      }

    }
  }

}
// 绑定编号接口
async function card_bind (bd_no) {
  const res = await commissionAPI.merchant.card_bind({
    extend_code: bd_no
  })
  if (res.error == 0) {//绑定成功

    uni.showModal({
      title: '提示',
      content: '绑定卡片成功',
      showCancel: false,
      success: function (res) {
        if (res.confirm) {
          console.log('用户点击确定');
        }
      }
    });
  } else {

    uni.showModal({
      title: '提示',
      content: res.msg,
      showCancel: false,
      success: function (res) {
        if (res.confirm) {
          console.log('用户点击确定');
        }
      }
    });
  }

}
// 绑定上级
async function bindParent (bd_no) {
  const res = await commissionAPI.merchant.bindParent({
    extend_code: bd_no
  })
  if (res.error == 0) {//未绑定过上下级，绑定成功
    uni.showModal({
      title: '提示',
      content: '绑定上级成功',
      showCancel: false,
      success: function (res) {
        if (res.confirm) {
          console.log('用户点击确定');
        }
      }
    });
    await getProfile()//查询信息获取上级id
    writeInfo()
  } else {//已经绑定过上下级-则查询该人上级信息填入
    uni.showModal({
      title: '提示',
      content: res.msg,
      showCancel: false,
      success: function (res) {
        if (res.confirm) {
          console.log('用户点击确定');
        }
      }
    });
    writeInfo()
  }

}
// 获取个人信息
async function getProfile () {
  await sheep.$store('user').getInfo()
}

// 填入当前用户上级信息
function writeInfo () {
  state.userInfo = sheep.$store('user').userInfo
  console.log('state.userInfo', state.userInfo)
  state.form.agency_name = state.userInfo.parent_user?.nickname
  state.form.agency_mobile = state.userInfo.parent_user?.mobile
}
// 填入当前用户信息
function myUserInfo () {
  state.userInfo = sheep.$store('user').userInfo
  console.log('state.userInfo', state.userInfo)
  state.form.agency_name = state.userInfo?.nickname
  state.form.agency_mobile = state.userInfo?.mobile
}

async function loginEnd (e) {
  await isMaker(sheep.$store('user').userInfo.mobile)
  state.userInfo = sheep.$store('user').userInfo
  await card_is_bind(state.bd_no)
}

function setValue (e, name) {
  form.value.setValue(name, e.detail.value);
}


function choosePos () {
  if (!state.disabled) {
    wx.chooseLocation({
      success (res) {
        console.log('获取成功', res)
        if (res.errMsg == 'chooseLocation:ok') {
          state.form.latitude = res.latitude
          state.form.longitude = res.longitude
          state.form.address = res.address
          state.pos_txt = res.address
        }
      },
      fail (err) {
        console.log('获取失败', err)
      }
    })
  }



}

onUnload(() => {

})
</script>

<style lang="scss" scoped>
.footer-message {
  font-size: 24rpx;
  font-weight: normal;
  color: #9e9e9e;
  border-bottom: 1rpx solid #f5f5f5;
  padding: 0 0 10rpx 10rpx;
}
.margin-top-style {
  margin-top: 20rpx;
}
.content-box {
  margin: 0 auto;
  width: 94%;
  // padding: 0 20rpx;
  background-color: #fff;
  border-radius: 20rpx;
  margin-top: 20rpx;
  overflow: hidden;
}
.color-style {
  color: #dd524d;
}
.bottom-box {
  width: 100%;
  position: fixed;
  left: 0;
  bottom: 0;
  z-index: 10;
  background-color: #fff;

  .btn-box {
    width: 686rpx;
    height: 88rpx;
    background: #1677fe;
    border-radius: 44rpx;
    font-weight: 500;
    font-size: 28rpx;
    color: #ffffff;
    line-height: 88rpx;
    text-align: center;
    position: relative;
  }

  .btn-withdraw {
    width: 686rpx;
    height: 88rpx;
    background: #dddddd;
    border-radius: 44rpx;
    font-weight: 500;
    font-size: 28rpx;
    color: #000000;
    line-height: 88rpx;
    text-align: center;
  }
}
.text-color {
  color: gray;
}
.radio-box {
  display: flex !important;
  justify-content: flex-end !important;
}
.bot-solid {
  padding-bottom: 20rpx;
  // border-bottom: 1rpx solid #f5f5f5;
}
.img-title {
  font-size: 32rpx;
  padding-bottom: 14rpx;
  margin-top: 10rpx;
}
.header-title {
  font-size: 32rpx;
  color: #323232;
  font-weight: 500;
  text-align: left;
  font-style: normal;
  padding: 24rpx 26rpx 0 26rpx;
}

.formItem-box {
  padding: 0 20rpx;
  background-color: #ffffff;
  .form-top-style {
    margin-top: 14rpx;
  }
  .form-box-input-item {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    height: 100%;
    width: 100%;
    // margin-top: 14rpx;

    input {
      // padding-top: 12rpx;
      width: 100%;
      font-size: 30rpx;
      text-align: right;
    }
  }
}
// ::v-deep .uni-forms-item__content {
//   display: flex;
//   align-items: center;
//   justify-content: flex-end;
// }
::v-deep .uni-forms-item__inner {
  padding-bottom: 0;
  padding-top: 20rpx;
  border-bottom: 1rpx solid #f5f5f5;
}
// ::v-deep .uni-error-message {

//   // padding-bottom: 0;
//   // padding-top: 20rpx;
//   // border-bottom: 1rpx solid #f5f5f5;
// }
::v-deep .none-border {
  .uni-forms-item__inner {
    border-bottom: none !important;
    padding-bottom: 0 !important;
  }
}
.img-content {
  display: flex;

  .footer-text {
    width: 100%;
    height: 36rpx;
    background: #5581fe;
  }
}

view {
  box-sizing: border-box;
}
.btn {
  width: 702rpx;
  height: 80rpx;
  background: #003288;
  border-radius: 49rpx;
  font-size: 32rpx;
  color: #ffffff;
}
.btn2 {
  width: 124rpx;
  height: 55rpx;
  line-height: 55rpx;
  background: #e8f1ff;
  border-radius: 28rpx;
  border: 2rpx solid #003288;
  font-size: 28rpx;
  color: #01338a;
}
.message-title-style {
  font-size: 24rpx;
  font-weight: normal;
  color: #9e9e9e;
}
::v-deep {
  // .radio__inner{
  // 	border-color: #ffdfc7!important;
  // }
  // .radio__inner-icon{
  // 	border-color: #ffdfc7!important;
  // 	background-color:var(--ui-BG-5)!important;
  // }
  .file-picker__box-content {
    border: none !important;
  }

  .uni-forms-item__inner {
    padding-bottom: 20rpx;
  }

  .uni-error-message {
    right: 0 !important;
    margin-top: -8rpx !important;
    display: flex;
    justify-content: flex-end;
    // height: 20rpx;
    // display: flex;
  }

  .uni-error-message-text {
    font-size: 20rpx;
    line-height: 1;
  }
  .uni-date {
    // margin-top: 16rpx;

    .uni-date-editor {
      display: flex;
      justify-content: flex-end;
      align-items: center;
      color: gray;
    }
  }
  .uni-input-input {
    color: gray;
  }
}

.form-box {
  width: 100%;
  border-radius: 24rpx 24rpx 0 0;
  background: #f8f8f8;
  padding-bottom: 60rpx;

  position: relative;
}
.morePic {
  width: 300rpx;
  height: 300rpx;
  line-height: 300rpx;
  background: #f5f4fc;
  font-size: 32rpx;
  text-align: center;
  margin-bottom: 20rpx;
}
.form-box-input-item-left {
  width: 100%;

  display: flex;
  justify-content: flex-start;
  align-items: center;

  view {
  }
}

::v-deep .uni-forms-item__label {
  width: max-content !important;
  .label-text {
    font-size: 30rpx;
  }
}

:deep().uni-radio-input {
  margin: 0 !important;
}

.form-box-head-title {
  font-weight: bold;
  font-size: 32rpx;
  color: #323232;
  text-align: left;
  font-style: normal;
}

.chongwu-zhaopian {
  width: 100rpx;
  height: 120rpx;
}
.status {
  width: 100%;

  .status-top {
    width: 100%;
    height: 130rpx;
    background-color: #fff;

    .status-wait {
      width: 100%;
      height: 130rpx;

      .status-wait-image {
        width: 64rpx;
        height: 64rpx;
      }

      .status-wait-title {
        font-weight: 500;
        font-size: 32rpx;
        color: #3d3d3d;
      }

      .status-wait-tips {
        font-weight: 500;
        font-size: 24rpx;
        color: #999999;
      }
    }
  }

  .status-bottom {
    width: 100%;
    height: 16rpx;
    background: #f3f3f3;
  }
}
</style>